/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.classnet.db;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author karltinawi
 */
@Entity
@Table(name = "email")
@NamedQueries({@NamedQuery(name = "Email.findByUser", query = "SELECT e FROM Email e WHERE e.emailPK.user = :user"), @NamedQuery(name = "Email.findByEmail", query = "SELECT e FROM Email e WHERE e.emailPK.email = :email")})
public class Email implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected EmailPK emailPK;
    @JoinColumn(name = "user", referencedColumnName = "email", insertable = false, updatable = false)
    @ManyToOne
    private User user1;

    public Email() {
    }

    public Email(EmailPK emailPK) {
        this.emailPK = emailPK;
    }

    public Email(String user, String email) {
        this.emailPK = new EmailPK(user, email);
    }

    public EmailPK getEmailPK() {
        return emailPK;
    }

    public void setEmailPK(EmailPK emailPK) {
        this.emailPK = emailPK;
    }

    public User getUser1() {
        return user1;
    }

    public void setUser1(User user1) {
        this.user1 = user1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (emailPK != null ? emailPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Email)) {
            return false;
        }
        Email other = (Email) object;
        if ((this.emailPK == null && other.emailPK != null) || (this.emailPK != null && !this.emailPK.equals(other.emailPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.classnet.db.Email[emailPK=" + emailPK + "]";
    }

}
